<?php
session_start();
$num = '';
$str = 'abcdefghijklmnopqrstuvwxyz0123456789';
for($i=0; $i<4; $i++){
    $num .= substr($str,mt_rand(0,35),1);
}
$_SESSION['captcha'] = $num;
$img = imagecreate(60,20);
$white = imagecolorallocate($img,255,255,255);
$blue = imagecolorallocate($img,0,0,255);
for($i=1; $i<200; $i++){
    $strx = mt_rand(1,60-9);
    $stry = mt_rand(1,20-9);
    $color = imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
    imagechar($img,1,$strx,$stry,'*',$color);
}
$strx = mt_rand(3,8);
for($i=0; $i<4; $i++){
    $stry = mt_rand(1,6);
    imagechar($img,5,$strx,$stry,substr($num,$i,1),$blue);
    $strx += mt_rand(8,13);
}
ob_clean();
header('Content-type:image/gif');
imagegif($img);